<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>消费记录管理</title>
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css"></head>
<body>
<h1>消费记录管理</h1>
<a href="adminHome.html" class="back-btn">返回管理员首页</a>
<!-- 显示消息 -->
<c:if test="${not empty message}">
  <div class="message">${message}</div>
</c:if>
<c:if test="${not empty error}">
  <div class="error">${error}</div>
</c:if>

<!-- 添加消费记录表单 -->
<div class="add-form">
  <h3>添加新消费记录</h3>
  <form action="ConsumptionServlet?action=add" method="post">
    <div class="form-group">
      <label for="memberId">会员ID：</label>
      <input type="number" id="memberId" name="memberId" required>
    </div>
    <div class="form-group">
      <label for="projectId">项目ID：</label>
      <input type="number" id="projectId" name="projectId" required>
    </div>
    <div class="form-group">
      <label for="consumeTime">消费时间：</label>
      <input type="datetime-local" id="consumeTime" name="consumeTime" required>
    </div>
    <div class="form-group">
      <label>&nbsp;</label>
      <input type="submit" value="添加消费记录">
    </div>
  </form>
</div>

<!-- 消费记录列表 -->
<h3>所有消费记录</h3>
<c:if test="${empty consumptionList}">
  <div style="color: #666; padding: 10px;">暂无消费记录</div>
</c:if>
<c:if test="${not empty consumptionList}">
  <table>
    <thead>
    <tr>
      <th>消费ID</th>
      <th>会员ID</th>
      <th>项目ID</th>
      <th>经理ID</th>
      <th>消费时间</th>
      <th>原价金额</th>
      <th>折扣金额</th>
      <th>实际金额</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${consumptionList}" var="consumption">
      <tr>
        <td>${consumption.consumptionId}</td>
        <td>${consumption.memberId}</td>
        <td>${consumption.projectId}</td>
        <td>${consumption.managerId}</td>
        <td><fmt:formatDate value="${consumption.consumeTime}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
        <td>¥ ${consumption.originalAmount}</td>
        <td>¥ ${consumption.discountAmount}</td>
        <td>¥ ${consumption.actualAmount}</td>

      </tr>
    </c:forEach>
    </tbody>
  </table>
</c:if>


</body>
</html>